<template>
  <el-dialog :title="title" :modal="false" :visible.sync="open" :before-close="handleCancel">
    <el-form :model="form" :rules="rules" ref="form" inline hide-required-asterisk>
      <el-col :span="24">
        <el-form-item label="会议名称：" prop="meetName">
          <el-input v-model="form.meetName" placeholder="请输入会议名称" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="会议类型：" prop="meetMode">
          <el-select v-model="form.meetMode" popper-class='meeting-select' :disabled="form.meetID ? true : false"
            placeholder="请选择会议类型">
            <el-option v-for="item in modeOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="默认发言：" prop="isAllowSpeak">
          <el-switch v-model="form.isAllowSpeak" active-color="#13ce66" inactive-color="#ff4949" active-text="开"
            inactive-text="关" active-value="yes" inactive-value="no"></el-switch>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="永许呼入：" prop="callinState">
          <el-switch v-model="form.callinState" active-color="#13ce66" inactive-color="#ff4949" active-text="开"
            inactive-text="关" active-value="1" inactive-value="0"></el-switch>
        </el-form-item>
      </el-col>
      <el-col :span="24" v-if="form.callinState === '1'">
        <el-form-item label="会议号码：" prop="callinNum">
          <el-input v-model="form.callinNum" placeholder="请输入会议号码" />
        </el-form-item>
      </el-col>
      <el-col :span="24" v-if="form.callinState === '1'">
        <el-form-item label="会议密码：" prop="callinPwd">
          <el-input v-model="form.callinPwd" placeholder="请输入会议密码" />
        </el-form-item>
      </el-col>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCommit" :loading.sync="loading" size="small">确定</el-button>
      <el-button @click="handleCancel" size="small">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    title: String,
    open: Boolean,
    form: {
      type: Object,
      default: () => {
        return {
          meetName: undefined,
          meetNum: undefined,
          meetID: undefined,
          isAllowSpeak: 'yes',
          meetMode: 'video',
          callinState: '0',
          callinNum: '',
          callinPwd: '',
        }
      },
    },
  },
  data() {
    return {
      modeOptions: [
        { label: '视频会议', value: 'video' },
        { label: '语音会议', value: 'audio' },
      ],
      rules: {
        meetName: [
          { required: true, message: '会议名称不能为空', trigger: 'blur' },
        ],
        isAllowSpeak: [
          { required: true, message: '会议类型不能为空', trigger: 'blur' },
        ],
        meetMode: [
          { required: true, message: '默认发言不能为空', trigger: 'blur' },
        ],
        callinState: [
          { required: true, message: '永许呼入不能为空', trigger: 'blur' },
        ],
        callinNum: [
          { required: true, message: '会议号码不能为空', trigger: 'blur' },
        ],
        callinPwd: [
          { required: true, message: '会议密码不能为空', trigger: 'blur' },
        ],
      },
      loading: false,
    }
  },
  methods: {
    // 确定按钮
    handleCommit() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          if (this.loading) return
          this.loading = true
          var res
          this.form.meetNum = this.form.meetName
          if (this.form.meetID) {
            // 修改会议
            SDK.modifyMeet(this.form)
              .then((res) => {
                this.handleCancel()
                this.loading = false
              })
              .catch((err) => {
                this.loading = false
                s
              })
          } else {
            // 添加会议
            SDK.createMeet(this.form)
              .then((res) => {
                this.handleCancel()
                this.loading = false
              })
              .catch((err) => {
                this.loading = false
                s
              })
          }
        }
      })
    },
    // 取消按钮
    handleCancel() {
      this.$emit('update:open', false)
    },
  },
}
</script>

<style lang="scss" scoped>
@import '~@/assets/scss/variable.scss';

::v-deep .el-dialog {
  background-color: #1a4969;
  width: px(600);
  top: 10vh;
  // min-height: 300px;
  // width: 40%;
  // margin: 0 !important;
  // position: absolute;
  // top: 50%;
  // left: 50%;
  // transform: translate(0, -50%);

  .el-dialog__header {
    padding: px(10) px(20);
    text-align: center;
    .el-icon-close,
    .el-dialog__title {
      color: #fff;
      font-size: px(18);
      line-height: px(24);
      height: px(24);
    }
  }
  .el-dialog__body {
    padding: px(10) px(20) 0;

    .el-form-item__error {
      font-size: px(12);
      line-height: px(20);
      padding: 0;
    }

    .el-form-item {
      width: 100%;
      margin-bottom: px(22);
      margin-right: px(10);
      display: flex;
      &__label,
      &__content {
        color: #ffffff;
        font-size: px(14);
        height: px(32);
        line-height: px(32);
      }
      &__content {
        flex: 1;
      }
      .el-input {
        width: 100%;
      }
      .el-input__inner {
        border-radius: px(5);
        height: px(32);
        line-height: px(32);
        background-color: #1a4969;
        color: #ffffff;
        font-size: px(14);
      }
    }
    .el-select {
      width: 100%;
      .el-input__icon {
        font-size: px(14);
        width: px(25);
        line-height: px(40);
      }
    }
    .el-switch {
      .el-switch__label * {
        font-size: px(14);
      }
      .el-switch__label {
        color: #ffffff;
        height: px(20);
        line-height: px(20);
        font-size: px(14);
        &.is-active {
          color: #13ce66;
        }
      }
      .el-switch__core {
        height: px(20);
        width: px(40) !important;
        border-radius: px(10);
        &::after {
          width: px(16);
          height: px(16);
          top: px(1);
          left: px(1);
        }
      }
      .el-switch__label--left {
        margin-right: px(10);
      }
      .el-switch__label--right {
        margin-left: px(10);
      }
    }
    .el-switch.is-checked .el-switch__core::after {
      margin-left: px(18);
    }
  }

  .el-button {
    background-color: #1a4969;
    color: #fff;
    height: px(30);
    line-height: px(30);
    width: px(70);
    font-size: px(12);
    border-radius: px(5);
    padding: 0;
    &:hover {
      background-color: #409eff;
    }
  }
}
</style>

<style lang="scss">
@import '~@/assets/scss/variable.scss';
.meeting-select .el-select-dropdown__wrap {
  background-color: #b4d2e6;
}

.meeting-select .popper__arrow::after {
  border-bottom-color: #b4d2e6 !important;
}

.meeting-select .el-select-dropdown__item {
  color: #ffffff !important;
  font-size: px(14);
  line-height: px(34);
  height: px(34);
  padding: 0 px(20);
}

.meeting-select .el-select-dropdown__item.hover,
.meeting-select .el-select-dropdown__item:hover {
  background-color: #3399ff !important;
}
</style>